<?php
/**
 * 后台基础控制器
 *
 * @author Dingwu
 */
namespace App\Admin\Controllers;

use App\Controllers\BaseController;

class BackendController extends BaseController {

    /**
     * 是否需要登录检测
     * @var bool
     */
    private $excludeLogin;

    /**
     * 不需要验证权限的接口
     * @var array
     */
    protected static $loginExcept = [];

    public function init() {
        parent::init();

        $this->excludeLogin = in_array($this->app['request']->getPathInfo(), static::$loginExcept);
        //$this->app['userAuth']->loginDetect($this->excludeLogin);
    }

    public function beforeAction(): bool
    {
        return parent::beforeAction();
    }

    public function beforeControllerAction(): bool
    {
        if (!$this->checkPermis()) {
            throw new \RuntimeException('Access Denied!', 403);
        }

        return parent::beforeControllerAction();
    }

    private function checkPermis() {
        if ($this->excludeLogin) {
            return true;
        }

        return true;
    }
}